<template>
	<view class="YmContent">
		<view class="main">
			<view class="title">
				<text>欢迎登录</text>
			</view>
			<view class="loginline"></view>
			<view class="line"></view>
			<view class="row">
				<text decode="true" class="text">工号/学号</text>
				<image src="/static/img/my/loginuser.png"></image>
				<input decode="true" class="mobile" @input="onKeyIdInput" v-model="Id" placeholder="请输入工号/学号"></input>
			</view>
			<view class="line"></view>
			<view class="row">
				<text decode="true" class="text">密码</text>
				<image src="/static/img/my/loginpwd.png"></image>
				<input password decode="true" class="mobile" @input="onKeyPasswordInput" v-model="Password" placeholder="请输入密码"></input>
			</view>
			<view class="line" style="margin-bottom: 30rpx;"></view>
			<button type="primary" @click="bindData" hover-class="none">确定</button>
		</view>
	</view>
</template>

<script>
	import {
		// getTest,
		minilogin
	} from '@/api/index/service.js';
	import {
		getMsgsReceive
	} from '@/api/my/service.js'
	var _this = this
	export default {
		data() {
			return {
				Id: null,
				Password: '',
				key: 1
			}
		},
		onLoad(options) {
			//options可以接到传过来的值
			console.log(options)
			if (options.key == 0) {
				this.key = 1
			}
			if (options.key == 1) {
				this.key = 3
			}
			if (options.key == 2) {
				this.key = 2
			}
		},
		methods: {
			onKeyIdInput: function(event) {
				this.Id = event.target.value
			},
			onKeyPasswordInput: function(event) {
				this.Password = event.target.value
			},
			bindData() {
				const open = uni.getStorageSync("userInfoOpenId")
				console.log(this.key, open, this.Id, this.Password)
				minilogin(this.key, open, this.Id, this.Password)
					.then(res => { 
						console.log(res);
						console.log(res.data.data.data);
						// role 1 teacher.. enterprise 2 ..stu 3
						if (res.data.data.role == 1) {
							uni.setStorageSync("role", "teacher");
							uni.setStorageSync("ID", res.data.data.data.tId);
							uni.setStorageSync("Teaid", res.data.data.data.tId);
						} else if (res.data.data.role == 2) {
							uni.setStorageSync("role", "enterprise");
							uni.setStorageSync("ID", res.data.data.data.eId);
							uni.setStorageSync("Eid", res.data.data.data.eId);

						} else if (res.data.data.role == 3) {
							uni.setStorageSync("role", "student");
							uni.setStorageSync("ID", res.data.data.data.stuId);
							uni.setStorageSync("Stuid", res.data.data.data.stuId);
							// uni.setTabBarItem({
							// 	index: 1,
							// 	// "pagePath": "pages/status02/status02",
							// 	"iconPath": "/static/img/status.png",
							// 	"selectedIconPath": "/static/img/select_status.png",
							// 	"text": "状态",
							// 	fail(res) {
							// 		console.log(res)
							// 	},
							// 	success(res) {
							// 		console.log(res)
							// 	}
							// })
						}
						uni.setStorageSync("Infomation", res.data.data.data);
						uni.setStorageSync("token", res.data.data.token);

						uni.switchTab({
							url: "/pages/index/index",
							success(res) {								
								console.log(res);
								uni.showToast({
									icon:'success',
									title: '登录成功'
								});
							},
							fail(res) {
								console.log(res);
							}
						})
					}).catch(res => {
						console.log(res);
						uni.showToast({
							icon:'none',
							title: '登录失败'
						});
					});
			},
		}
	};
</script>

<style>
	page {
		background-color: rgba(245, 245, 245, 1);
	}

	.title {
		color: rgba(78, 78, 78, 1);
		text-align: center;
		font-weight: bold;
	}

	.title text {
		font-size: 18pt;
	}

	.loginline {
		background-color: rgba(53, 125, 197, 1);
		margin: 10px auto;
		width: 36pt;
		height: 4pt;
		border-radius: 20%;

	}

	.main {
		margin-top: 70px;
		margin-left: 5rpx;
	}

	.row {
		color: rgba(78, 78, 78, 1);
	}

	.row text {
		padding-left: 30rpx;
		font-size: 10pt;
	}

	.row input {
		padding-top: 10rpx;
		padding-left: 30rpx;
		font-size: 9pt;
	}

	.row image {
		width: 16pt;
		height: 18.11pt;
		float: left;
		position: relative;
		top: 40rpx;
		left: 16rpx;
	}

	.line {
		white-space: normal;
		width: 749upx;
		height: 1upx;
		padding: 0upx;
		clear: both;
		margin-top: 36upx;
		margin-left: 0upx;
		float: left;
		background-color: #e1e1e1;
		text-align: left;
		border-radius: 0upx;
		font-size: 2upx;
		line-height: 3upx;
	}

	button[type=primary] {
		background-color: rgba(53, 125, 197, 1);
	}

	button {
		color: #fff;
		width: 90%;
		border-radius: 30px;
		/* 		line-height: 2.1; */
	}

	button::after {
		color: #fff;
		border: 1px solid rgba(53, 125, 197, 1);
	}

	input {
		font-size: 10pt;
	}
</style>
